﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestHook
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
            
            System.Tools.Hook.Keyboard.HookKeyboard.SetHook();

            System.Tools.Hook.Keyboard.HookKeyboard.OnHook    += new EventHandler<System.Tools.Hook.Keyboard.HookEvent>(HookKeyboard_OnHook);
            System.Tools.Hook.Keyboard.HookKeyboard.OnKeyDown += new EventHandler<System.Tools.Hook.Keyboard.HookEvent>(HookKeyboard_OnKeyDown);
            System.Tools.Hook.Keyboard.HookKeyboard.OnKeyUp   += new EventHandler<System.Tools.Hook.Keyboard.HookEvent>(HookKeyboard_OnKeyUp);           
        }

        void HookKeyboard_OnKeyUp(object sender, System.Tools.Hook.Keyboard.HookEvent e)
        {
            tbHook.Text += "UP Code = " + e.code.ToString() + " lParam = " + e.lParam.ToString() + " wParam = " + e.wParam.ToString() + "\r\n";
        }

        void HookKeyboard_OnKeyDown(object sender, System.Tools.Hook.Keyboard.HookEvent e)
        {
            tbHook.Text += "DOWN Code = " + e.code.ToString() + " lParam = " + e.lParam.ToString() + " wParam = " + e.wParam.ToString() + "\r\n";
        }

        void HookKeyboard_OnHook(object sender, System.Tools.Hook.Keyboard.HookEvent e)
        {
            tbHook.Text += "Code = " + e.code.ToString() + " lParam = " + e.lParam.ToString() + " wParam = " + e.wParam.ToString()+"\r\n";

        }

        private void mainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Tools.Hook.Keyboard.HookKeyboard.UnHook();
        }
    }
}
